﻿// CSplashDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "CSplashDlg.h"
#include "afxdialogex.h"


// CSplashDlg 对话框

IMPLEMENT_DYNAMIC(CSplashDlg, CDialogEx)

CSplashDlg::CSplashDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CSplashDlg, pParent)
{
	if (Create(CSplashDlg::IDD, (CWnd*)pParent))
	{
		ShowWindow(SW_HIDE);
	}
}

CSplashDlg::~CSplashDlg()
{
}

void CSplashDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSplashDlg, CDialogEx)
	ON_WM_PAINT()
END_MESSAGE_MAP()


// CSplashDlg 消息处理程序


BOOL CSplashDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CRect rt;
	GetClientRect(rt);
	int cx = GetSystemMetrics(SM_CXSCREEN); // 获取屏幕宽度
	int cy = GetSystemMetrics(SM_CYSCREEN); // 获取屏幕宽度
	MoveWindow(cx / 2 - rt.Width() / 2, cy / 2 - rt.Height() / 2, rt.Width(), rt.Height());
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CSplashDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: 在此处添加消息处理程序代码
					   // 不为绘图消息调用 CDialogEx::OnPaint()
	CRect rect;
	GetClientRect(rect);
	rect.InflateRect(-1, -1);
	DrawBaseMap(&dc, rect, IDB_SPLASH);
}

//绘制底图
void	CSplashDlg::DrawBaseMap(CDC* pDC, CRect rtArea, long nMapID)
{
	if (nMapID < 0) return;
	CDC srcDC;
	if (srcDC.CreateCompatibleDC(pDC))
	{
		if (bmpBK.LoadBitmap(MAKEINTRESOURCE(nMapID)))
		{
			CBitmap *pOldBmp = srcDC.SelectObject(&bmpBK);
			// Get the size of the bitmap.
			BITMAP bm;
			bmpBK.GetObject(sizeof(bm), &bm);
			int nBmpHeight = bm.bmHeight;
			int nBmpWidth = bm.bmWidth;

			pDC->StretchBlt(
				rtArea.left, rtArea.top,
				rtArea.Width(), rtArea.Height(),
				&srcDC,
				0, 0,
				bm.bmWidth, bm.bmHeight,
				SRCCOPY);

			srcDC.SelectObject(pOldBmp);
			bmpBK.DeleteObject();
		}
	}
	srcDC.DeleteDC();
	ReleaseDC(&srcDC);
}